<template>
  <div>
    <header class="header_3d">
   
    
      <!-- 头部的第一行 -->
      <div class="top">
        <div class="container">
          <div class="loginList" >
            <p @click="goHome()">惠乡平台欢迎您！</p>
          
            <p v-if="!$store.state.user.nickName">
              <span>请</span>
              <router-link to="/login">登录</router-link>
              <router-link to="/register" class="register"
                >免费注册</router-link
              >
            </p>
          
            <p v-else>
              <a> {{ $store.state.user.nickName }}</a>
              <a class="register" @click="loginOut">退出登录</a>
            </p>
          </div>
          <div class="typeList">
            <router-link to="/center/myorder">我的订单</router-link>
            
            <router-link to="/shopcart">我的购物车</router-link>
            <router-link to="/DaoTian">关注农村</router-link>
            <a href="###">会员</a>
            <a href="###">企业采购</a>
         
            <a href="###">合作招商</a>
            <a href="###">商家后台</a>
          </div>
        </div>
      </div>
      
      <!--头部第二行 搜索区域-->
      <div class="bottom">
      
        <h1 class="logoArea" v-if="this.$route.meta.show_3Dpic">  
          <a class="logo" title="logo" @click="goHome()">
            <img src="/images/logo.png" alt="" />
          </a>
        </h1>  
        <div>
          <a  class="box_3d" @click="goDaoTian()" v-if="this.$route.meta.show_3Dpic"></a>
        </div>
        <div class="searchArea" v-if="this.$route.meta.show_3Dpic">
          <form action="###" class="searchForm">
            <input
              type="text"
              id="autocomplete"
              class="input-error input-xxlarge"
              v-model="keyword"
            />
            <button
              class="sui-btn btn-xlarge btn-danger"
              type="button"
              @click="goSearch"
            >
              搜索
            </button>
          </form>
        </div>
      </div>
     
    </header>

  </div>
</template>

<script>
import deep_3d from '@/components/3d动图/index'
export default {
  
  name: "MyHeader",
  data() {
    return {
      keyword: "",
    };
  },
  components:{
    deep_3d
  },
  methods: {
    goSearch() {
      if (this.$route.query) {
        let location = {
          name: "Search",
          params: { keyword: this.keyword || undefined },
          query: this.$route.query,
        };
        this.$router.push(location);
      }
    },
    goHome(){

      this.$router.push({ name: "home" });
    
    },
    goDaoTian(){
      // console.log(11);
      this.$router.push({name:"DaoTian"})
      
    },
    goDaoTian(){
      // console.log(11);
      this.$router.push({name:"DaoTian"})
      
    },
    goDaoTian(){
      // console.log(11);
      this.$router.push({name:"DaoTian"})
      
    },
    // 派发退出登陆请求
    async loginOut() {
      try {
        let result = await this.$store.dispatch("getloginOut");
        
        this.$router.push("/home");
      } catch (error) {
        alert(error);
      }
    },
  },

  

  mounted() {
    this.$bus.$on("clear", () => {
      this.keyword = "";
    });
  },
};
</script>

<style lang="less" scoped>
.show3d{
  margin: 25px 60px;
}
.header_3d {
  
  & > .img_3d{
    position: absolute;
  
  }
  & > .top {
    position: relative;
    z-index: 999;
    height: 30px;
    line-height: 30px;
    .container {
      width: 1200px;
      margin:0 auto;
      z-index: 999;
      background-color: #ffffff69;
      overflow: hidden;

      .loginList {
        float: left;

        p {
          float: left;
          margin-right: 15px;

          .register {
            border-left: 1px solid #b0a8a8;
            padding: 0 5px;
            margin-left: 5px;
          }
        }
      }

      .typeList {
        float: right;

        a {
          padding: 0 10px;

          & + a {
            border-left: 1px solid #b3aeae;
          }
        }
      }
    }
  }

  & > .bottom {
    position: relative;
   
    z-index: 999;
    width: 1200px;
    
    margin: -9px auto;
    overflow: hidden;
    
    .logoArea {
      float: left;
      .logo {
        img {
          width: 100px;
          margin: 25px 0px;
         
        }
      }
    }
    .box_3d{
      float: left;
      width: 300px;
      height: 150px;
      
    }
    .searchArea {
      float: right;
      margin-top: 70px;
      margin-right: 20px;
      height: 50px;

      .searchForm {
        overflow: hidden;

        input {
          box-sizing: border-box;
          width: 490px;
          height: 32px;
          padding: 0px 4px;
          border: 2px solid #ea4a36;
          float: left;

          &:focus {
            outline: none;
          }
        }

        button {
          height: 32px;
          width: 68px;
          background-color: #ea4a36;
          border: none;
          color: #fff;
          float: left;
          cursor: pointer;

          &:focus {
            outline: none;
          }
        }
      }
    }
  }
}
</style>